<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Application_model extends CI_Model {

    
    function create($update_data) {
        
        $create_data['created_at'] = time();
        $this->db->insert('applications', $update_data);

        return $this->db->insert_id();
    }

    function edit($id, $edit_data) {
        return $this->db->where('application_id', $id)->update('applications', $edit_data);
    }
    
    function get($id) {
        return $this->db->select('*')->where('application_id', $id)
                        ->get('applications')->row_array();
    }
    
    
    function payin($id){
        $this->db->where('application_id', $id)->update('applications', array('payment_status' => 'Pay-in'));
        return TRUE;
    }
    
    function payment_complete($id){
        $this->db->where('application_id', $id)->update('applications', array('payment_status' => 'Complete'));
        return TRUE;
    }
    
    function get_id_by_fb($facebook_id){
        
        $count = $this->db->where('facebook_id', $facebook_id)
                        ->count_all_results('applications');
        if($count){
            return $this->db->select('application_id')->where('facebook_id', $facebook_id)
                        ->get('applications')->row()->application_id;
        }else{
            return FALSE;
        }
        
    }
}
